<template>
  <div class="p-16px">
    <el-card>
      <el-form label-width="160px">
        <el-form-item label="设备商品数量预警阈值">
          <el-space>
            <el-input-number
              v-model="form.deviceGoodsNumWarnPercent"
              :min="0"
              :max="100"
              @change="handleChange"
            >
              <template #suffix>%</template>
            </el-input-number>
          </el-space>
        </el-form-item>
        <el-form-item label="烤箱提示信息">
          <el-input
            v-model="form.warnNotifyInfo"
            type="textarea"
            style="width: 500px"
            :autosize="{ minRows: 3, maxRows: 10 }"
          ></el-input>
        </el-form-item>
        <el-form-item label="轮播图">
          <el-select v-model="form.swiperAdId" style="width: 500px">
            <el-option label="请选择" value=""></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="待机广告">
          <el-select v-model="form.standbyAdId" style="width: 500px">
            <el-option label="请选择" value=""></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="广告音量">
          <el-input-number
            v-model="form.adVolume"
            :min="0"
            :max="15"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="提示音量">
          <el-input-number
            v-model="form.notifyVolume"
            :min="0"
            :max="7"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="静音时间段" style="width: 450px">
          <el-time-picker
            v-model="form.muteTime"
            is-range
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          ></el-time-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="handleSubmit"
            :loading="submitLoading"
          >
            保存
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useCommonStoreHook } from "@/store/modules/common";

const commonStore = useCommonStoreHook();
const form = ref({
  deviceGoodsNumWarnPercent: 0,
  warnNotifyInfo: "",
});
const submitLoading = ref(false);

const handleChange = () => {};
const handleSubmit = () => {
  submitLoading.value = true;
  console.log(form.value);
  commonStore
    .saveOrUpdateGlobalConfig(form.value)
    .then(() => {
      ElMessage.success("保存成功");
    })
    .finally(() => {
      submitLoading.value = false;
    });
};
const fetchConfig = () => {
  commonStore.getGlobalConfig().then((res) => {
    form.value = res;
  });
};
onMounted(() => {
  fetchConfig();
});
</script>

<style lang="scss" scoped></style>
